package com.aduerr.v1shouyin.mvp.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;
import com.aduerr.v1shouyin.R;
import com.aduerr.v1shouyin.entity.AppDetailEntity;

import java.util.List;

/**
 * 网络监测adapter
 * Created by fyf on 2018/4/23 0023.
 */

public class NetworkAdapter extends RecyclerView.Adapter {

    private List<AppDetailEntity> entityList;
    private Context context;
    private ViewHolder viewHolder;

    public NetworkAdapter(Context context, List<AppDetailEntity> entityList) {
        this.context = context;
        this.entityList = entityList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_network_list,
                parent, false);
        viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        viewHolder = (ViewHolder) holder;
        viewHolder.tvNetworkDetail.setText(entityList.get(position).getApp_msg());
        viewHolder.tvNetworkTitle.setText(entityList.get(position).getTitle());
    }

    @Override
    public int getItemCount() {
        if(entityList.size() > 0) return entityList.size();
        return 0;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_network_title)
        TextView tvNetworkTitle;
        @BindView(R.id.tv_network_detail)
        TextView tvNetworkDetail;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
